$(function() {
	var data = window.sessionStorage.getItem('myData');
    if (!data) {
        window.location = 'login.html';
    }; 
    var url = 'http://ittalentsapi.bashibozuk.eu/users/change-password?X-GameID=103';
    $('#chpbutton').click(function(event){
		event.preventDefault();
		var myData = {};
		myData.email = $('#email').val();
		myData.password = $('#password').val();
		myData.password_repeat = $('#password_repeat').val();
		console.log(myData);
		$.ajax(url, {
			method: 'POST',
			cache:false,
			data : myData,
			crossDomain : true,
			success: function(data) {
				if(data.errors) {
					$('.errors').html('');
					for(i in data.errors) {
						$('.errors').html(data.errors[i].join('<br>'));
					}
				}
				else {
					$('.errors').html('Your password has been changed !');
				}
			}
		});		
	});
});